﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using A5Lib;
using System.Text.RegularExpressions;

namespace A5Services
{
    public class UserServices : IUserServices
    {
       

        public bool ValidateUser(string username, string password)
        {
            return XMLDataManager.ValidateUser(username, password);
        }

        public bool CheckUsernameExists(string username)
        {
            return XMLDataManager.CheckUsernameExists(username);
        }


        public User GetUser(string username)
        {
            return XMLDataManager.GetUser(username);
        }

        public bool WriteUser(User u, bool newUser)
        {
            return XMLDataManager.WriteUser(u, newUser);
        }


        public User ChangeUsername(User u, string newUsername)
        {
            return XMLDataManager.ChangeUsername(u, newUsername);
        }

        public List<string> GetAllUsernames()
        {
            return XMLDataManager.GetAllUsernames();
        }


        public bool DeleteUser(string username)
        {
            return XMLDataManager.DeleteUser(username);
        }

        public bool InputValidator(string input, int minChars, int maxChars, bool allowSpaces)
        {
            string allowedChars = allowSpaces ? "[a-zA-Z0-9 ]" : "[a-zA-Z0-9]";
            if(Regex.Match(input, allowedChars + "{" + minChars + "," + maxChars + "}").Value == input) return true;

            return false;
        }
    }
}
